home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / libx11.lha / libX11 / xmdrawing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-22  |  6.6 KB  |  269 lines

  1. /* Copyright (c) 1996 by Terje Pedersen.  All Rights Reserved   */
  2. /*                                                              */
  3. /* By using this code you will agree to these terms:            */
  4. /*                                                              */
  5. /* 1. You may not use this code for profit in any way or form   */
  6. /*    unless an agreement with the author has been reached.     */
  7. /*                                                              */
  8. /* 2. The author is not responsible for any damages caused by   */
  9. /*    the use of this code.                                     */
  10. /*                                                              */
  11. /* 3. All modifications are to be released to the public.       */
  12. /*                                                              */
  13. /* Thats it! Have fun!                                          */
  14. /* TP                                                           */
  15. /*                                                              */
  16.  
  17. /***
  18.    NAME
  19.      drawing
  20.    PURPOSE
  21.      add some drawing funcs to libX11
  22.    NOTES
  23.      these funcs uses MUI objects to draw in.
  24.    HISTORY
  25.      Terje Pedersen - Oct 22, 1994: Created.
  26. ***/
  27.  
  28. #include <intuition/intuition.h>
  29. #include <graphics/gfx.h>
  30. #include <graphics/gfxmacros.h>
  31. #include <graphics/regions.h>
  32.  
  33. #include <proto/intuition.h>
  34. #include <proto/graphics.h>
  35.  
  36. #include <dos.h>
  37. #include <string.h>
  38. #include <stdlib.h>
  39. #include <stdio.h>
  40.  
  41. #include "libX11.h"
  42.  
  43. #define XLIB_ILLEGAL_ACCESS 1
  44.  
  45. #include <X11/X.h>
  46. #include <X11/Xlib.h>
  47.  
  48. #include <libraries/mui.h>
  49. #include <proto/muimaster.h>
  50.  
  51. #include "amigax_proto.h"
  52. #include "amiga_x.h"
  53.  
  54. /*******************************************************************************************/
  55. /* externals */
  56.  
  57. extern struct RastPort *Arp;
  58. extern struct Window *rootwin;
  59. extern GC      amiga_gc;
  60. extern int X_relx,X_rely;
  61. extern struct Screen *Scr,*wb;
  62.  
  63. extern struct Region *clipWindow(struct Layer *l,
  64.                  LONG minX, LONG minY, LONG maxX, LONG maxY);
  65.  
  66. /*******************************************************************************************/
  67. /* prototypes */
  68.  
  69. #include "amigax_proto.h"
  70.  
  71. #define MAX_COORD 200 /* 100 vertices, 5 bytes each = 500 bytes. */ 
  72.  
  73. typedef struct {
  74.   void * win_rastptr; /* PLANEPTR */
  75.   int AWidth,AHeight,max_coords;
  76.   WORD *coor_buf;
  77.   struct TmpRas win_tmpras /*,*oldtmpras*/;
  78.   struct AreaInfo win_AIstruct;
  79.   int background;
  80. } X11userdata;
  81.  
  82. X11userdata *XMuserdata=NULL;
  83. struct TmpRas *oldtmpras;
  84. struct AreaInfo *oldarea;
  85.  
  86. Window XMprevwin=NULL;
  87. GC XMprevgc=NULL;
  88.  
  89. int X11muiapp=0;
  90.  
  91. Object *_muicanvas;
  92.  
  93. UBYTE *Xm_set_area(int w,int h);
  94.  
  95. #define M_PI      3.14159265358979323846
  96.  
  97. #define rad(x) ((double)(x)*M_PI/180)
  98.  
  99. /*******************************************************************************************/
  100. /*** functions ***/
  101.  
  102. int isopen(Object *win){
  103.   LONG open;
  104. /*
  105. #ifdef DEBUGXEMUL
  106.   printf("isopen %d\n",win);
  107. #endif
  108. */
  109.   if(win){
  110.     if(_win(win)){
  111.       get(_win(win),MUIA_Window_Open,&open);
  112.       if(open) return(1);
  113.     }
  114.   }
  115.   return(0);
  116. }
  117.  
  118. int _passit=0;
  119.  
  120. struct Region *old_region;
  121.  
  122. XRectangle oldrec;
  123.  
  124. void XmSetClipRectangles(Display *d,Object *win,GC gc,int clip_x_origin,
  125.            int clip_y_origin, XRectangle *rectangles, int n, int ordering)
  126. {
  127.   int right;
  128.   int bottom;
  129.   
  130.   if(_passit){XSetClipRectangles(d,gc,clip_x_origin,clip_y_origin,rectangles,n,ordering); return;}
  131.   bottom=_mtop(win)+rectangles[0].y+rectangles[0].height-1;
  132.   right=_mleft(win)+rectangles[0].x+rectangles[0].width-1;
  133. #ifdef DEBUGXEMUL
  134.   printf("XsetClipRectangles\n");
  135. #endif
  136.   if(bottom>_mbottom(win))bottom=_mbottom(win)-1;
  137.   if(right>_mright(win))right=_mright(win)-1;
  138.   if(win){
  139.     struct Window *w=_window(win);
  140.     if(old_region=clipWindow(w->WLayer,_mleft(win)+rectangles[0].x,_mtop(win)+rectangles[0].y,right,bottom)){
  141.       oldrec.x=old_region->bounds.MinX;
  142.       oldrec.y=old_region->bounds.MinY;
  143.       oldrec.width=old_region->bounds.MaxX;
  144.       oldrec.height=old_region->bounds.MaxY;
  145.       DisposeRegion(old_region);
  146.     }
  147.   }
  148. }
  149.  
  150. void XmSetClipMask(Object *win, Pixmap pixmap)
  151. {
  152. #ifdef DEBUGXEMUL
  153.   printf("XSetClipMask\n");
  154. #endif
  155.   if(_passit){ XSetClipMask(win,NULL,pixmap); return;}
  156.   if(win){
  157.     struct Window *w=_window(win);
  158.     unclipWindow(w->WLayer);
  159. /*    oldrec.x=0;oldrec.y=0;oldrec.width=w->Width; oldrec.height=w->Height;
  160.     clipWindow(w->WLayer,oldrec.x,oldrec.y,oldrec.width,oldrec.height);*/
  161.   }
  162. }
  163.  
  164. XmCenterMapWindow(Window win,int dx,int dy,int w,int h)
  165. {
  166.   Object *mwin=X11DrawablesMUI[X11DrawablesMap[win]];
  167. #ifdef DEBUGXEMUL
  168.   printf("CenterMapWindow\n");
  169. #endif
  170.   if(_passit){/*XCenterMapWindow(win,dx,dy,w,h); */return;}
  171.   set(mwin,MUIA_Window_Open,TRUE);
  172.   return;
  173. }
  174.  
  175. void Xm_settemp(Object *win,UBYTE *data){
  176.   X11userdata *ud=(X11userdata*)data;
  177.   if(isopen(win)){
  178.     if(_rp(win)){
  179.       oldtmpras=(_rp(win))->TmpRas;
  180.       oldarea=(_rp(win))->AreaInfo;
  181.       (_rp(win))->TmpRas=&(ud->win_tmpras);
  182.       (_rp(win))->AreaInfo = &(ud->win_AIstruct);
  183.       _window(win)->UserData=data;
  184.     }
  185.   }
  186. }
  187.  
  188. void Xm_remtemp(Object *win){
  189.   if(isopen(win)){
  190.     if(_rp(win)){
  191.       _rp(win)->TmpRas=oldtmpras;
  192.       _rp(win)->AreaInfo=oldarea;
  193.     }
  194.   }
  195. }
  196.  
  197.  
  198.  
  199.  
  200.  
  201. /*
  202. XmUnmapWindow(Display *d,Object *window){
  203. #ifdef DEBUGXEMUL
  204.   printf("XmUnmapWindow\n");
  205. #endif
  206.   if(_passit) {XUnmapWindow(d,window); return;}
  207.   if(window!=NULL) set(window,MUIA_Window_Open,FALSE);
  208.   return(0);
  209. }
  210.  
  211. XmMapRaised(Object *window){
  212.   LONG open;
  213. #ifdef DEBUGXEMUL
  214.   printf("XmMapWindow\n");
  215. #endif
  216.   if(_passit) {XMapRaised(NULL,window); return;}
  217.   if(window) set(window,MUIA_Window_Open,TRUE);
  218.   get(window,MUIA_Window_Open,&open);
  219.   if(!open) return(BadWindow);
  220.   return(0);
  221. }
  222. */
  223.  
  224. XSetCanvas(Drawable win){
  225.   _muicanvas=X11DrawablesMUI[X11DrawablesMap[win]];
  226. }
  227.  
  228. XSetRootwin(Drawable win){
  229.   rootwin=_window(win);
  230. }
  231.  
  232. XSetPass(n){
  233.   extern Window prevwin;
  234.   extern GC prevgc;
  235.   _passit=n;
  236.   if(n) init_area(rootwin,MAX_COORD,DG.nDisplayWidth,DG.nDisplayHeight);
  237.   else exit_area(rootwin);
  238.   prevwin=NULL;
  239.   prevgc=NULL;
  240.   XMprevwin=NULL;
  241.   XMprevgc=NULL;
  242. }
  243.  
  244. XmPutImage(display, d, gc, image, src_x, src_y,
  245.       dest_x, dest_y, width, height)
  246.      Display *display;
  247.      Drawable d;
  248.      GC gc;
  249.      XImage *image;
  250.      int src_x, src_y;
  251.      int dest_x, dest_y;
  252.      unsigned int width, height;
  253. {
  254.   XPutImage(display,_window(d),gc,image,src_x,src_y,_mleft(d)+dest_x,_mtop(d)+dest_y,width,height);
  255. }
  256.  
  257. Status XmGetWindowAttributes(display, w, window_attributes_return)
  258.      Display *display;
  259.      Window w;
  260.      XWindowAttributes *window_attributes_return;
  261. {/*    File 'image_f_io.o'*/
  262.   Window win=Agetwin(w);
  263. #ifdef DEBUGXEMUL0
  264.   printf("XGetWindowAttributes\n");
  265. #endif
  266.   XGetWindowAttributes(display,_window(w),window_attributes_return);
  267.   return(0);
  268. }
  269.